package com.ymttest.database.sqlwapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.YmtTradingItem;
import com.ymttest.utils.EnvSetup;

public class YmtTradingItemWapper {
	SqlManager manage;

	public YmtTradingItemWapper() {
		manage = new SqlManager("ymt" + EnvSetup.getEnv());
	}

	public int getTradingId(int OrderId) {
		List<YmtTradingItem> list = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtTradingItemMapper.selectTradingIdByOrderId", OrderId);
		Integer TradingId = list.get(0).getItradingid();
		// Logger.debug(TradingId);
		return TradingId;
	}
	
	public int getMaxTradingId(int OrderId){
		List<YmtTradingItem> list = manage.getSelectResults(
				"com.ymttest.database.mapping.YmtTradingItemMapper.selectMaxTradingIdByOrderId", OrderId);
		Integer TradingId = list.get(0).getItradingid();
		// Logger.debug(TradingId);
		return TradingId;
	}
	
	public List<Map> selectTradingItem(String queryField, String joinCondition, String queryCondition) {
		Map m = new HashMap();
		if(null != queryField && !"".equals(queryField)){
			m.put("queryField", queryField);
		}
		if(null != joinCondition && !"".equals(joinCondition)){
			m.put("joinCondition", joinCondition);
		}
		if(null != queryCondition && !"".equals(queryCondition)){
			m.put("queryCondition", queryCondition);
		}
		return (List<Map>) manage.getSelectResults(
				"com.ymttest.database.mapping.YmtTradingItemMapper.selectTradingItem", m);
	}

	/**
	 * 关闭数据库连接
	 */
	public void close() {
		manage.close();
	}

	@Override
	protected void finalize() throws Throwable {
		this.close();
		manage = null;
		super.finalize();
	}

	public static void main(String[] args) {
		YmtTradingItemWapper test = new YmtTradingItemWapper();
//		test.getTradingId(500384405);
		test.selectTradingItem("top 1 *", "", "1=1");
	}
}
